package com.unicomcz.login;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.unicomcz.ActionBase;

public class ForgetPasAction extends ActionBase
{
    private String mobile="";
    private String valCode="";
    /**
     * @return the mobile
     */
    public String getMobile()
    {
        return mobile;
    }
    /**
     * @param mobile the mobile to set
     */
    public void setMobile(String mobile)
    {
        this.mobile = mobile;
    }
    /**
     * @return the valCode
     */
    public String getValCode()
    {
        return valCode;
    }
    /**
     * @param valCode the valCode to set
     */
    public void setValCode(String valCode)
    {
        this.valCode = valCode;
    }
    public String execute() throws Exception{
        boolean dbFlag = setupConn("dls");
        if (!dbFlag) {
            log.debug(mobile+"找回密码失败!因为建立数据库连接失败");
            return "error";
        }
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();
        log = Logger.getLogger(this.getClass());
        String volidateCode = (String)session.getAttribute("VALIDATE_FORGETPAS");
       if ((valCode == null)||(valCode.compareTo(volidateCode)!=0)) {
           addActionMessage("验证码输入错误！");
           return "error";
       }
       /*
       String[] userInfo = getSingle("SELECT depart_id,passwd FROM DLS_CODE_DLS WHERE mobile=? AND status=0");
       if (userInfo == null) {
           //找不到号码
           addActionMessage("找不到您输入的号码，请确认号码正确！");
           return "error"; 
       }*/
       //现在发送短信
       int rtv = execProc("{call sms_pas(?,?)}",2);
       if (rtv == 0) {
           addActionMessage("用户名、密码已经通过短信发送到您的手机，请耐心等待！");
       }else if (rtv == -1){
           addActionMessage("您输入的手机号码不存在！");
       }else {
           addActionMessage("找回密码失败，请与片区经理联系！");
       }
       return SUCCESS;
    }
    protected void regProcParam() {
        try {
            log.debug(mobile);
           cstmt.setString(1, mobile);
           
        }catch(Exception e) {
            
        }
        
    }

}
